package com.joolun.web.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.controller.BaseWxController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.core.page.TableDataInfo;
import com.joolun.mall.config.CommonConstants;
import com.joolun.mall.domain.ArticleCategory;
import com.joolun.mall.entity.GoodsSpu;
import com.joolun.mall.service.IArticleCategoryService;
import com.joolun.mall.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/article")
@Api(value = "article", tags = "小程序文章")
public class Article extends BaseWxController {


    @Autowired
    private IArticleCategoryService articleCategoryService;

    @Autowired
    private IArticleService articleService;

    /**
     * 返回文章分类列表
     */
    @ApiOperation(value = "文章分类列表")
    @GetMapping("/category")
    public AjaxResult articleCategoryList(ArticleCategory articleCategory) {
        List<ArticleCategory> list = articleCategoryService.selectArticleCategoryList(articleCategory);
        return AjaxResult.success(list);
    }



    /**
     * 查询文章管理列表
     */
    @ApiOperation(value = "文章列表")
    @GetMapping("/list")
    public TableDataInfo list(com.joolun.mall.domain.Article article)
    {
        startPage();
        List<com.joolun.mall.domain.Article> list = articleService.selectArticleList(article);
        return getDataTable(list);
    }


    /**
     * 获取文章信息
     */
    @ApiOperation(value = "文章详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getArticleInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(articleService.selectArticleById(id));
    }
}
